/****************************************************************************
**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
*****************************************************************************
**  Copyright (c) 2008-2019                                                **
**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/

/*!
 * \file
 */

#ifndef SION_SION_GENERIC_APIDESC_H
#define SION_SION_GENERIC_APIDESC_H

#include "sion_const.h"
#include "sion_datatypes.h"

#define SION_GENERIC_API_LEVEL_NONE 70
#define SION_GENERIC_API_LEVEL_STD  71
#define SION_GENERIC_API_LEVEL_FULL 72

/* container describing API generated by the generic API */
struct _sion_generic_apidesc_struct {
  int    aid; 
  char  *name; 
  int   level; 

  /* STD callbacks */
  int  (*create_lcg_cb)(void **, void *, int, int, int, int, int, int);
  int  (*free_lcg_cb)(void *);

  int  (*barrier_cb)(void *);
  int  (*bcastr_cb)(void *,void *, int,int,int);
  int  (*gatherr_cb)(void *,void *,void *,int,int,int);
  int  (*gathervr_cb)(void *,void *,void *,int, int *, int, int);
  int  (*scatterr_cb)(void *,void *,void *,int, int, int);
  int  (*scattervr_cb)(void *,void *,void *,int, int *, int, int);
  char *(*get_multi_filename_cb)(const char *,int);

  /* callbacks for coalescing */
  int  (*gather_execute_cb)(const void *, sion_int64*, int, sion_int64,
			    void *, int, int, int, int,
			    int process_cb(const void *,sion_int64 *, int));
  int  (*execute_scatter_cb)(void *, sion_int64*, int, sion_int64,
			    void *, int, int, int, int,
			    int process_cb(void *,sion_int64 *, int));
  int  (*get_capability_cb)(void *);

};
typedef struct _sion_generic_apidesc_struct _sion_generic_apidesc;

_sion_generic_apidesc * _lsion_generic_alloc_apidesc(void);
int _lsion_generic_init_apidesc(  _sion_generic_apidesc *sion_apidesc );
int _lsion_generic_free_apidesc(  _sion_generic_apidesc *sion_apidesc );


/* container describing additional data needed for each SION file opened with an API generated by the generic API */
struct _sion_generic_gendata_struct {
  _sion_generic_apidesc* apidesc;
  int    aid; 
  int    grank;
  int    gsize;
  int    lrank;
  int    lsize;
  int    filenumber;
  int    numfiles;
  void  *comm_data_global;
  void  *comm_data_local;
};
typedef struct _sion_generic_gendata_struct _sion_generic_gendata;

_sion_generic_gendata * _lsion_generic_alloc_gendata(void);
int _lsion_generic_init_gendata(  _sion_generic_gendata *sion_gendata );
int _lsion_generic_free_gendata(  _sion_generic_gendata *sion_gendata );

int _lsion_generic_update_api_level(  _sion_generic_apidesc *sion_gendata );

#endif
